<script>
/*
 * @Author: Your name
 * @Date:   2020-06-23 18:09:06
 * @Last Modified by:   Your name
 * @Last Modified time: 2020-06-24 09:08:21
 */
</script>
<template>
    <div class="tabbarItem" @click="itemClick">
        <div v-if="!isActive">
            <slot name="item-icon"></slot>
        </div>
        <div v-else>
            <slot name="active-item-icon"></slot>
        </div>
        <div :style="colorStyle">
            <slot name="item-text"></slot>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            
        }
    },
    props:{
        path:String,
        textColor:{
            type:String,
            default:"hotpink"
        }
    },
    computed:{
        isActive(){
            return this.$route.path.indexOf(this.path)!=-1;
        },
        colorStyle(){
            return this.isActive?{color:this.textColor}:{};
        }
    },
    methods:{
        itemClick(){
            this.$router.replace(this.path);
            // this.$router.push(this.path);
            // console.log(this);   //输出Vuecomponent
            // console.log(this.$router);  //输出vue-router的实例对象
        }
    }
}
</script>
<style lang="css">
    .tabbarItem{
        flex: 1;
        text-align: center;
    }
    .tabbarItem img{
        width: 25px;
        height: 25px;
        vertical-align: middle;
        margin-top: 5px;
    }
    .tabbarItem .text{
        font-size: 12px;
        margin-top: 1px;
    }
</style>